﻿<!DOCTYPE html>
<html>
<head>
    <title>链接添加修改</title>
    $css()

</head>
<body>
    <style type="text/css">
        #bind {
            width: 350px;
            position: absolute;
            left: 330px;
            top: 8.7em;
            line-height: 30px;
            display: none;
        }

            #bind div.label {
                width: 60px;
                margin-right: -60px;
            }

            #bind div.in {
                margin-left: 60px;
            }
    </style>

    <div id="dataPanel" style="padding:2em 0 2em 1em">
        <div class="form">
            <div class="title" style="margin-top: 0">
                <span class="icon icon1"></span>${form_title}
            </div>


            <div>

                <div class="fl hidden">
                    <div class="label">绑定：</div>
                    <div class="in">
                        <input type="hidden" field="Type" />
                        <input type="hidden" field="Id" />

                        <input type="hidden" field="BindId" id="bindid" />
                        <input type="hidden" field="BindType" id="bindtype" />

                        <span id="bindtip" field="BindTitle"></span>&nbsp;&nbsp;

                        <span class="ui-button w80 small-button" id="cancelbind" onclick="cancelBind()">
                            <span class="button-inner">
                                <span class="button-txt">取消绑定</span>
                                <a href="javascript:;"></a>
                            </span>
                        </span>
                    </div>
                </div>


                <div class="fl">
                    <div class="label">文字：</div>
                    <div class="in">
                        <input type="text" class="ui-validate ui-box" required="true" length="[0,50]" field="Text" id="text" />
                    </div>
                </div>

                <div class="fl" id="urlpanel">
                    <div class="label">地址：</div>
                    <div class="in">
                        <input type="text" class="ui-validate ui-box" length="[0,255]" field="Uri" id="uri" size="45" />
                        <br /><span class="msg" style="color: #777;">路径请以"/"开头,外站链接请加"http://"</span>
                    </div>

                </div>
                <div class="fl">
                    <div class="label">图片：</div>
                    <div class="in">
                        <input type="text" class="ui-validate ui-box" length="[0,100]" field="ImgUrl" id="imgurl" tipin="imgurl_tip" placeholder="选填" /><br />

                        <span class="ui-button w80 small-button" id="upload">
                            <span class="button-inner">
                                <span class="button-txt">选择图片</span>
                                <a href="javascript:;"></a>
                            </span>
                        </span>

                    </div>
                </div>

                <div class="fl">
                    <div class="label">顺序：</div>
                    <div class="in">
                        <input type="text" class="ui-validate ui-box" isnumber="true" field="SortNumber" id="SortNumber" style="width: 30px" /><span class="msg">显示的顺序,如:1</span>
                    </div>
                </div>

                <div class="fl">
                    <div class="label">打开方式：</div>
                    <div class="in">
                        <select class="ui-box" field="Target">
                            <option value="">本窗口</option>
                            <option value="_blank">新窗口</option>
                        </select>
                    </div>
                </div>

                <div class="fl">
                    <div class="label">是否显示：</div>
                    <div class="in">
                        <input id="visible1" type="radio" name="Visible" field="Visible" value="True" checked="checked" style="border: none" />
                        <label for="visible1">显示</label>
                        <input id="visible2" type="radio" name="Visible" field="Visible" value="False" style="border: none" />
                        <label for="visible2">隐藏</label>
                    </div>
                </div>

                <div class="fl">
                    <div class="label">&nbsp;</div>
                    <div class="in">
                        <span class="ui-button w150" id="btn">
                            <span class="button-inner">
                                <span class="button-txt" field="Btn">保存</span>
                                <a href="javascript:;"></a>
                            </span>
                        </span>
                    </div>
                </div>

            </div>

            <div id="bind">

                <div class="fl">
                    <div class="label">继承于：</div>
                    <div class="in">
                        <select field="Pid" id="pid" class="ui-box">
                            <option value="0">一不继承一</option>${parent_opts}
                        </select>
                    </div>
                </div>

                <div class="fl">
                    <div class="label">绑定栏目：</div>
                    <div class="in">
                        <select name="categoryid" id="cate_sel" field="CategoryId" class="left ui-box" style="width: 200px">
                            <option value="">一请选择栏目一</option>
                            ${category_opts}
                        </select>

                        <span class="ui-button w50 middle-button" onclick="cateBind()">
                            <span class="button-inner">
                                <span class="button-txt">绑定</span>
                                <a href="javascript:;"></a>
                            </span>
                        </span>
                    </div>

                </div>


                <div class="fl">
                    <div class="label">绑定文档：</div>
                    <div class="in">
                        <input class="ui-box left archiveGuess" type="text" id="title" style="width: 192px" />
                        <span class="ui-button w50 middle-button" id="btn_search_archive">
                            <span class="button-inner">
                                <span class="button-txt">绑定</span>
                                <a href="javascript:;"></a>
                            </span>
                        </span>
                    </div>
                </div>

                <div class="clearfix"></div>

            </div>

        </div>
    </div>

    $js()
    <script type="text/javascript">
        jr.json.bind('dataPanel',${entity});

        var bindid = jr.$('bindid'),
              bindtype = jr.$('bindtype'),
              bindtip = jr.$('bindtip'),
              cancelbind = jr.$('cancelbind'),
              linkurl = jr.$('urlpanel');

        cancelbind.style.display = bindtip.innerHTML == '未绑定' ? 'none' : '';
        //linkurl.style.display = cancelbind.style.display != 'none' ? 'none' : '';

        var upload = jr.upload({
            id: 'upload',
            url: '?module=upload&action=uploadimage&for=link&upload.id=upload',
            exts: '*.gif;*.jpg;*.png;*.bmp'
        },function (result, data) {
            if (result) {
                jr.$('imgurl').value = data.url;
            } else {
                alert('上传失败：' + data);
            }
        });

        var currentGuess = null;
        jr.each(jr.dom.getsByClass(jr.$('dataPanel'), 'archiveGuess'), function (i, e) {
            jr.autoCompletion(e, '?module=ajax&action=GetSearchArchivesJsonResult&size=10&only_title=true&site_id=${site_id}', function (data) {
                currentGuess = null;
                for (var j = 0; j < data.length; j++) {
                    data[j].text =data[j].title;
                    data[j].archiveTitle = data[j].title;
                    data[j].title = '栏目：' + data[j].category;
                }
            }, function (data) {
                currentGuess = data;
            });
        });

        jr.$('btn_search_archive').onclick = function() {
            if (currentGuess == null) {
                showErr('请选择正确的文档');
            } else {
                bind({ id: currentGuess.id, text: currentGuess.archiveTitle, type: "archive" });
            }
        };

        function bind(data) {
            var id = data.id,
              text = data.text,
              type = data.type;

            if (id != '') {
                var typeStr = '';
                switch (type) {
                    case 'archive': typeStr = '文档'; break;
                    case 'category': typeStr = '栏目'; break;
                }

                bindid.value = id;
                bindtype.value = type;
                bindtip.innerHTML = typeStr + ':' + text;
                jr.$('cancelbind').style.display = '';
                linkurl.style.display = 'none';
            }
            currentGuess = null;
        }

        function cateBind() {
            var cateSel = jr.$('cate_sel');
            bind({id:cateSel.value,text:cateSel.options[cateSel.selectedIndex].innerHTML,type:'category'});
        }

        function cancelBind() {
            bindid.value = '';
            bindtype = '';
            bindtip.innerHTML = '未绑定';
            jr.$('cancelbind').style.display = 'none';
            linkurl.style.display = '';
        }

        window.saveData = function onsubmit() {

            if (jr.validator.validate()) {
                jr.xhr.jsonPost(
                       '?module=link&action=save'
                       , jr.json.toObject('dataPanel')
                       , function (json) {
                           if (json.result) {
                               showMsg2(json.message,function(){ location.replace('?module=link&action=list&type=${link_type}');});
                           } else {
                               showErr(json.message);
                           }

                       });
            }
        };


        jr.$('btn').onclick = window.saveData;

    </script>
</body>
</html>